//我的邀请码链接
var page = 1;
var limit = 10;
var isloadCount = false;
var Main = function() {
	var _this = this;
	mui('#refreshContainer').pullToRefresh({
		down: {
			callback: function() {
				var self = this;
				_this.loadList(1, function() {
					self.endPullDownToRefresh();
				});
				page = 1;
			}
		},
		up: {
			callback: function() {
				var self = this;
				if(page == 1) {
					page++;
				}
				_this.loadList(page++, function() {
					self.endPullUpToRefresh();
				});

			}
		}
	})
	this.init();
	this.even();
	this.loadList(page); //加载推荐人列表
};
Main.prototype = {
	init: function() {
		mui('.mui-scroll-wrapper').scroll({
			indicators: true //是否显示滚动条
		});

		Date.prototype.format = function(format) {
			var o = {
				"M+": this.getMonth() + 1,
				"d+": this.getDate(),
				"h+": this.getHours(),
				"m+": this.getMinutes(),
				"s+": this.getSeconds(),
				"q+": Math.floor((this.getMonth() + 3) / 3),
				"S": this.getMilliseconds()
			}
			if(/(y+)/.test(format)) {
				format = format.replace(RegExp.$1, (this.getFullYear() + "")
					.substr(4 - RegExp.$1.length));
			}
			for(var k in o) {
				if(new RegExp("(" + k + ")").test(format)) {
					format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] :
						("00" + o[k]).substr(("" + o[k]).length));
				}
			}
			return format;
		}
	},
	even: function() {},
	loadList: function(page, _callback) {
		var _this = this;
		var url = server_url + "/user/findAllRecommandPersonBpCustMember.do";
		var param = {
			isMobile: isMobile,
			memberId: Util.getLoginUser().memberId,
			page: page,
			limit: limit,
		}
		$.getJSON(url, param, function(retData) {
			var html = '';
			if(retData.success) {
				var list = retData.result; 
				if(!isloadCount) {
					var totalCount = retData.totalCounts;
					var $totalCount = new CountUp("total-count", 0, totalCount, 0, 1);
					$totalCount.start();
					isloadCount = true;
				}

				for(var i = 0; i < list.length; i++) {
					html += "<dl class='row'>\n";
					html += "<dd>" + list[i].loginname + "</dd>\n";
					html += "<dd>" + new Date(list[i].registrationDate).format("yyyy-MM-dd hh:mm:ss") + "</dd>\n";
					html += "</dl>\n";
				}
			}
			if(page == 1) {
				$('.m-recommend-list').html('');
			}
			$('.m-recommend-list').append(html);

			if($.isFunction(_callback)) {
				_callback();
			}
		});

	}
}